//
//  SimpleTimer.swift
//  SimpleCal
//
//  Created by 杜晓祥 on 2021/10/25.
//

import Foundation


class SimpleTimer {
    static let shared = SimpleTimer()
    private var today:DateEntity!
    
    private init () {
        t = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(dateTimeTask(_:)), userInfo: nil, repeats: true)
    }
    
    private var t:Timer!
    
    @objc private func dateTimeTask (_ sender: Any) {
        let date = CalendarUtil.getNowDateEntity()
        
        if today != nil {
            if !today.equal(date: date) {
                GlobalControl.shared.monthSwitch?.update()
            }
        }
        today = date
        GlobalControl.shared.window?.updateStatus(value: date.getFormatterDefault())
    }
    
    func fire() {
        t.fire()
    }
    
}
